package cn.yikaojiuguo.student.ui.ask;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import cn.yikaojiuguo.student.R;
import cn.yikaojiuguo.student.support.utils.Util;
import cn.yikaojiuguo.student.support.utils.ViewUtils;
import cn.yikaojiuguo.student.ui.base.BasePopupWindow;

/**
 * Created by cfan_yang on 2016/1/15.
 */
public class AskPopupWindow extends BasePopupWindow implements View.OnClickListener{

    private TextView mTv_take;
    private TextView mTv_choose;
    private TextView mTv_record;
    private TextView mTv_cancel;

    public AskPopupWindow(Context context, float widthPercent, float heightPercent) {
        super(context, widthPercent, heightPercent);
    }

    @Override
    protected void initEvent() {
        mTv_take.setOnClickListener(this);
        mTv_choose.setOnClickListener(this);
        mTv_record.setOnClickListener(this);
        mTv_cancel.setOnClickListener(this);
    }

    @Override
    protected void initView(Context context) {
        mTv_take = ViewUtils.find(mConvertView,R.id.tv_take);
        mTv_choose = ViewUtils.find(mConvertView,R.id.tv_choose);
        mTv_record = ViewUtils.find(mConvertView,R.id.tv_record);
        mTv_cancel = ViewUtils.find(mConvertView,R.id.tv_cancel);
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.item_popup_ask;
    }

    @Override
    public void dismiss() {
        super.dismiss();
        Util.lightOn((Activity) mContext);
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        if(parent == null) {
            super.showAtLocation(((Activity) mContext).getWindow().getDecorView(), gravity, x, y);
        } else {
            super.showAtLocation(parent,gravity,x,y);
        }
        Util.lightOff((Activity) mContext);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_take:
                mContext.startActivity(AskActivity.newIntent(AskActivity.TAKE_PHOTO));
                dismiss();
                break;
            case R.id.tv_choose:
                mContext.startActivity(AskActivity.newIntent(AskActivity.CHOOSE_PIC));
                dismiss();
                break;
            case R.id.tv_record:
                mContext.startActivity(AskRecordActivity.newIntent());
                dismiss();
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }
}
